package com.cf.studiomanage.controller;

import com.cf.studiomanage.entity.Assessment;
import com.cf.studiomanage.service.AssessmentService;
import com.cf.studiomanage.util.R;

import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/assessments")
@Tag(name = "个人评测模块", description = "活跃度/技能/贡献评测相关接口")
public class AssessmentController {

    @Autowired
    private AssessmentService service;

    @PostMapping("/add")
    @Operation(summary = "添加评测记录", description = "管理员添加用户评测得分")
    public R add(@RequestBody Assessment assessment) {
        return service.add(assessment) ? R.ok("添加成功") : R.error("添加失败");
    }

    @GetMapping("/user/{userId}")
    @Operation(summary = "查看用户评测", description = "查看某用户的所有评测记录")
    public R getByUser(@PathVariable Long userId) {
        return R.ok().data("list", service.getByUser(userId));
    }

    @GetMapping("/top/{type}")
    @Operation(summary = "查看评测排行", description = "查看某类评测（如活跃度）TOP 10")
    public R topByType(@PathVariable String type) {
        return R.ok().data("list", service.top10ByType(type));
    }

    @DeleteMapping("/{id}")
    @Operation(summary = "删除评测记录", description = "根据 ID 删除评测")
    public R delete(@PathVariable Long id) {
        return service.deleteById(id) ? R.ok("删除成功") : R.error("删除失败");
    }
}
